<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%
String path = request.getContextPath();
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>日志列表</title>
    <link href="<%=path%>/css/core.css" rel="stylesheet" type="text/css"/>
    <link href="<%=path%>/css/form.css" rel="stylesheet" type="text/css"/>
    <link href="<%=path%>/css/list.css" rel="stylesheet" type="text/css"/>
    <link href="<%=path%>/css/blog.css" rel="stylesheet" type="text/css"/>
    <link href="<%=path%>/css/xToolbar.css" rel="stylesheet" type="text/css"/>
    <link href="<%=path%>/css/jquery-impromptu.css" rel="stylesheet" type="text/css"/>
    <link href="<%=path%>/css/UsersSelect.css" rel="stylesheet" type="text/css"/>
    <link href="<%=path%>/css/xWindowPanel.css" rel="stylesheet" type="text/css"/>
  </head>
  <body>
    <div id="toolbar"></div>
    <form id="listForm" class="search-div" action="<%=path%>/daily/blog/search.t4m" method="post">
      <s:hidden name="searchType"/>
      <input type="hidden" id="result" name="result" value="success"/>
      <input type="hidden" name="forDate" value="<s:date name="forDate" format="yyyy-MM-dd"/>"/>
      <div class="search-condition">
        <table class="search-table" cellspacing="0" cellpadding="0">
          <tr>
            <td class="c-left">内容：</td>
            <td><input name="searchValue" type="text" class="text" value="<s:property value="searchValue[0]"/>"/></td>
            <td class="c-left">标签：</td>
            <td><input name="searchValue" type="text" class="text" value="<s:property value="searchValue[1]"/>"/></td>
          </tr>
          <tr>
            <td class="c-left">发表时间：</td>
            <td><input name="searchValue" id="minD" type="text" class="text Wdate" value="<s:property value="searchValue[2]"/>" onclick="WdatePicker({maxDate:'#F{$dp.$D(\'maxD\')}'});"/></td>
            <td class="c-left">到：</td>
            <td><input name="searchValue" id="maxD" type="text" class="text Wdate" value="<s:property value="searchValue[3]"/>" onclick="WdatePicker({minDate:'#F{$dp.$D(\'minD\')}'});"/></td>
          </tr>
          <tr>
            <td class="c-left">创建人：</td>
            <td colspan="3"><input id="creator" name="searchValue" type="hidden" value="<s:property value="searchValue[4]"/>"/></td>
          </tr>
        </table>
      </div>
      <div class="search-commit">
        <a href="javascript:void(0)" class="search-button" onclick="$('#searchType').val('and');$('#listForm').submit();">与查询</a>
        <a href="javascript:void(0)" class="search-button" onclick="$('#searchType').val('or');$('#listForm').submit();">或查询</a>
      </div>
    </form>
    <div id="blog" class="blog">
      <s:bean id="forDate" name="java.util.Date"/>
      <s:iterator id="blog" value="blogList" status="i">
        <s:if test="#forDate.getTime() != #blog.forDate.getTime()">
          <s:set name="creatorId" value=""/>
          <s:if test="#i.index > 0">
                    </ul>
                  </div>
                </li>
              </ul>
            </div>
          </s:if>
          <s:set name="forDate" value="#blog.forDate"/>
          <div class="blog-line">
            <div class="blog-date">
              <div class="blog-date-year"><s:date name="#blog.forDate" format="yyyy-MM"/></div>
              <div class="blog-date-d"><s:date name="#blog.forDate" format="dd"/></div>
            </div>
            <ul class="blog-content">
        </s:if>
        <s:else>
          <s:if test="#blog.creator.id != #creatorId">
                </ul>
              </div>
            </li>
          </s:if>
        </s:else>
        <s:if test="#blog.creator.id != #creatorId">
          <s:set name="creatorId" value="#blog.creator.id"/>
          <li>
            <div class="blog-personal">
              <div class="personal-head" style="background-image:url('<%=path%><s:if test="#blog.creator.normalImage == null">/image/UsersSelect/grid_sex_<s:property value="#blog.creator.sex"/>.png</s:if><s:else><s:property value="#blog.creator.normalImage"/></s:else>');"></div>
              <ul>
        </s:if>
              <li class="blog-data-line" id="<s:property value="#blog.id"/>" creator="<s:property value="#blog.creator.id"/>">
                <s:if test="#blog.isShare == @org.team4.constants.StringConstant@TRUE">
                  <div class="blog-tags" style="background-color:#000000;">共享</div>
                </s:if>
                <s:iterator id="tags" value="#blog.tagsList">
                  <div class="blog-tags" style="background-color:<s:property value="#tags.color"/>;"><s:property value="#tags.name"/></div>
                </s:iterator>
                <span class="blog-text"><s:property value="#blog.contents"/></span>
                <span class="blog-data-date"><s:date name="#blog.createTime" format="yyyy-MM-dd HH:mm"/></span>
                <s:if test="#blog.blogReplyList.size > 0">
                  <div class="blog-reply-arrows"></div>
                  <div class="blog-reply-contents">
                    <s:iterator id="blogReply" value="#blog.blogReplyList">
                      <s:if test="#blogReply.isPT == @org.team4.constants.StringConstant@FALSE || #blog.creator.id == #session['LoginBean'].user.id || #blogReply.creator.id == #session['LoginBean'].user.id">
                        <div class="blog-reply-data <s:property value="#blogReply.creator.id"/>" id="<s:property value="#blogReply.id"/>" style="background-image: url('<%=path%><s:if test="#blog.creator.smallImage == null">/image/UsersSelect/list_sex_<s:property value="#blogReply.creator.sex"/>.png</s:if><s:else><s:property value="#blogReply.creator.smallImage"/></s:else>')">
                          <s:if test="#blogReply.isPT == @org.team4.constants.StringConstant@TRUE">
                            <div class="pt-img"></div>
                          </s:if>
                          <s:property value="#blogReply.contents"/>
                          <span class="blog-data-date"><s:date name="#blogReply.createTime" format="yyyy-MM-dd HH:mm"/></span>
                        </div>
                      </s:if>
                    </s:iterator>
                  </div>
                </s:if>
              </li>
      </s:iterator>
        </li>
      </div>
    </div>
    <script src="<%=path%>/js/tinyMCE/tiny_mce.js" type="text/javascript"></script>
    <script src="<%=path%>/js/jquery.js" type="text/javascript"></script>
    <script src="<%=path%>/js/core.js" type="text/javascript"></script>
    <script src="<%=path%>/js/Upload.js" type="text/javascript"></script>
    <script src="<%=path%>/js/share.js" type="text/javascript"></script>
    <script src="<%=path%>/js/UsersSelect.js" type="text/javascript"></script>
    <script src="<%=path%>/js/xWindowPanel.js" type="text/javascript"></script>
    <script src="<%=path%>/js/Draggable.js" type="text/javascript"></script>
    <script src="<%=path%>/js/xToolbar.js" type="text/javascript"></script>
    <script src="<%=path%>/js/xToolbar.items.js" type="text/javascript"></script>
    <script src="<%=path%>/js/Validate.js" type="text/javascript"></script>
    <script type="text/javascript">
    $(document).ready(function(){
    
      new UsersSelect({
        url : '<%=path%>/system/ajax/listMetaUsers.t4m?moduleId=<s:property value="@com.voa.constants.OAStringConstant@BLOG_ID"/>',
        inputId : 'creator',
        title : '选择创建人',
        width : 403,
        multiple : true
      });
      
      new Toolbar({
        id: '1',
        renderTo : 'toolbar',
        icon: '../../image/op.gif',
        items : [{
          type:'button',
          text:'新建',
          useable : 'T',
          position: {
            a: '0px 0px',
            b: '0px -120px'
          },
          handler:function(){
            top.blog.add();
          }
        },'-',{
          type:'button',
          text:'隐藏标签',
          useable : 'T',
          position: {
            a: '0px 0px',
            b: '0px -120px'
          },
          handler:function(entity){
            toggleTags(entity);
          }
        },'-',{
          type: 'search'
        },'-',{
          type:'button',
          text:'刷新',
          position: {
            a: '-60px 0px',
            b: '-60px -120px'
          },
          handler:function(){
            $('#listForm').submit();
          }
        },{
          type: 'filters',
          active: '<s:property value="result"/>',
          items: [{
            id : 'aggregation',
            tip : '聚合浏览',
            position: {
              a: '-100px -240px'
            },
            handler : function(){
              changeViewType('aggregation');
            }
          },{
            id : 'success',
            tip : '微博浏览',
            position: {
              a: '-80px -240px'
            },
            handler : function(){
              changeViewType('success');
            }
          }]
        }]
      });
      
      $('.blog-data-line').hover(function(){
        var _self = $(this);
        var _op = $('.op', this);
        if(_op.length > 0) {
          _op.show();
          return;
        }
        var htmlArray = [];
        htmlArray.push('<div class="op">');
        htmlArray.push('<div class="op-button" title="回复日志" style="background-position:-40px -241px;" onclick="showReplyBlog(\''+_self.attr('id')+'\')"></div>');
        if(_self.attr('creator') === '<s:property value="#session['LoginBean'].user.id"/>') {
          <s:if test="@org.team4.util.Meta@getOperate(\"blog_edit\") == @org.team4.constants.StringConstant@TRUE">
            htmlArray.push('<div class="op-button" title="修改日志" style="background-position:-20px 0px;" onclick="editBlog(\''+_self.attr('id')+'\')"></div>');
          </s:if>
          <s:if test="@org.team4.util.Meta@getOperate(\"blog_delete\") == @org.team4.constants.StringConstant@TRUE">
            htmlArray.push('<div class="op-button" title="删除日志" style="background-position:-43px 0px;" onclick="deleteBlog(\''+_self.attr('id')+'\')"></div>');
          </s:if>
        }
        htmlArray.push('</div>');
        _self.append(htmlArray.join(''));
      }, function(){
        var _op = $('.op', this);
        var tinyMCEs = $('textarea', this);
        if(tinyMCEs.length === 0) {
          _op.hide();
          return;
        }
        tinyMCEs.each(function(){
          if(tinyMCE.get($(this).attr('id')).getContent() === '') {
            $(this).parent().hide();
            _op.hide();
            $('#blog').focus();
          }
        });
      });
      
      addReplyHover();
      
      $('#blog').height($(document.body).height() - $('#toolbar').outerHeight() - 8);
      $('.blog-content').width($(document.body).width() - 98);
      $('.blog-data-line').width($(document.body).width() - 94 - 70);
      loadReady();
    });
    
    function addReplyHover() {
      $('.<s:property value="#session['LoginBean'].user.id"/>').unbind().hover(function(){
        var _self = $(this);
        var _op = $('.reply-op-button', this);
        if(_op.length > 0) {
          _op.show();
          return;
        }
        var htmlArray = [];
        htmlArray.push('<div class="reply-op-button" title="删除回复" style="background-position:-41px 0px;" onclick="deleteReply(\''+_self.attr('id')+'\')"></div>');
        _self.prepend(htmlArray.join(''));
      }, function(){
        var _op = $('.reply-op-button', this);
        _op.hide();
      });
    }
    
    function showReplyBlog(id) {
      if($('#reply-'+id).length > 0) {
        $('#reply-'+id).parent().show();
        return;
      }
      var htmlArray = [];
      htmlArray.push('<div class="blog-reply">');
      htmlArray.push('<textarea class="textarea" id="reply-'+id+'"></textarea>');
      htmlArray.push('<input class="btn-1 reply" type="button" value="回复" onclick="replyBlog(\''+id+'\');"/>');
      htmlArray.push('<label class="pt"><input id="pt-'+id+'" type="checkbox" value="T"/> 悄悄话</label>');
      htmlArray.push('</div>');
      $('#'+id).append(htmlArray.join(''));
      tinyMCE.init({
        // General options
        mode : "exact",
        elements : "reply-"+id,
        theme : "advanced",
        language : "zh",
        
        // Theme options
        theme_advanced_buttons1 : "bold,italic,underline,strikethrough,forecolor,|,backcolor,|,undo,redo,|,code",
        theme_advanced_buttons2 : "",
        theme_advanced_buttons3 : "",
        theme_advanced_toolbar_location : "top",
        theme_advanced_toolbar_align : "left",
        theme_advanced_resizing : false,
        theme_advanced_path : false,
        force_br_newlines : true,
        force_p_newlines : false,
        forced_root_block : '',
        theme_advanced_font_sizes : "12px,14px,16px,18px,20px,24px",
    
        // Example content CSS (should be your site CSS)
        content_css : "<%=path%>/css/tinyMCE/content.css"
      });
    }
    
    function replyBlog(id) {
      var contents = tinyMCE.get('reply-'+id).getContent();
      if(contents === '') {
        alert('难道不想说点什么？');
      } else {
        $.ajax({
          url : '<%=path%>/ajax/blog/reply.t4m',
          data : {
            'blogReply.blog.id': id,
            'blogReply.contents': contents,
            'blogReply.isPT': $('#pt-'+id).attr('checked') ? 'T' : 'F'
          },
          success : function(json) {
            tinyMCE.get('reply-'+id).setContent('');
            var dataLine = $('#'+id);
            var replyContents = $('.blog-reply-contents', dataLine);
            var noReply = replyContents.length === 0;
            $('#reply-'+id).parent().hide();
            var htmlArray = [];
            if(noReply) {
              htmlArray.push('<div class="blog-reply-arrows"></div><div class="blog-reply-contents">');
            }
            htmlArray.push('<div id="'+json.id+'" class="blog-reply-data <s:property value="#session['LoginBean'].user.id"/>" style="background-image: url(\'<%=path%><s:if test="#session['LoginBean'].user.smallImage == null">/image/UsersSelect/list_sex_<s:property value="#session['LoginBean'].user.sex"/>.png</s:if><s:else><s:property value="#session['LoginBean'].user.smallImage"/></s:else>\')">');
            if(json.isPT === 'T') {
              htmlArray.push('<div class="pt-img"></div>');
            }
            htmlArray.push(json.contents);
            htmlArray.push(' <span class="blog-data-date">');
            htmlArray.push(json.createTime);
            htmlArray.push('</span>');
            htmlArray.push('</div>');
            if(noReply) {
              htmlArray.push('</div>');
              $('.op', dataLine).before(htmlArray.join(''));
            } else {
              replyContents.append(htmlArray.join(''));
            }
            addReplyHover();
          }
        });
      }
    }
    
    function editBlog(id) {
      top.blog.update(id);
    }
    
    function deleteBlog(id) {
      var txt = '是否删除该信息？';
      $.prompt(txt,{
        buttons:{删除:true,取消:false},
        callback: function(v,m) {
          if(v) {
            $.ajax({
              url : '<%=path%>/ajax/blog/deleteBlog.t4m',
              data : 'id='+id,
              success : function(json) {
                var blog = $('#'+json);
                var blogLine = blog.parents('.blog-line');
                var personLine = blog.parents('.blog-personal');
                var persons = $('.blog-personal', blogLine);
                var lines = $('.blog-data-line', blog.parents('.blog-personal'));
                if(lines.length === 1 && persons.length === 1) {
                  blogLine.remove();
                } else if(lines.length === 1) {
                  personLine.parent().remove();
                } else {
                  blog.remove();
                }
              }
            });
          }
        }
      });
    }
    
    function deleteReply(id) {
      var txt = '是否删除该信息？';
      $.prompt(txt,{
        buttons:{删除:true,取消:false},
        callback: function(v,m) {
          if(v) {
            $.ajax({
              url : '<%=path%>/ajax/blog/deleteReply.t4m',
              data : 'id='+id,
              success : function(json) {
                var reply = $('#'+id);
                var replyContents = reply.parent();
                if($('.blog-reply-data', replyContents).length === 1) {
                  reply.parent().prev().remove();
                  reply.parent().remove();
                } else {
                  reply.remove();
                }
              }
            });
          }
        }
      });
    }
    
    function changeViewType(result) {
      $('#result').val(result);
      $('#listForm').submit();
    }
    
    function toggleTags(entity) {
      if($('.blog-tags').css('display') === 'block'){
        $('.blog-tags').hide();
        entity.setText('显示标签');
      } else {
        $('.blog-tags').show();
        entity.setText('隐藏标签');
      }
    }
    </script>
  </body>
</html>